from conn_mysql_redis import ConnRedis, ConnMysql, InsertConnMysql
from sanic.response import json
import asyncio
import json
from .is_phone_test import is_phone
from sendsms.send_sms import SendSms
class Register():

    async def register(self,phone,verify_code,password):

        if not all((phone,verify_code,password)):

            return {'status':-1,'errorCode':1,'errorMsg':'请检查你的参数','resultBody':None}
        if not is_phone(phone):

            return {'status':-1,'errorCode':2,'errorMsg':'请检查你的手机号','resultBody':None}

            
        with await ConnRedis().pool_ as c:
        await c.select(1)
        info=await c.get(phone)

        if info:

            if info=verify_code:

                return True
            else:

                return False
        else:

            return {
                'status': -1,
                'errorCode': 4,
                'errorMsg': '验证码失效,请重新请求',
                'resultBody': None
                }

        user_sql="""insert into user(user_phone,user_pwd)
                values
                (%s,%s,%s,%s,%s)"""

        info=InsertConnMysql().insert_info(user_sql,(phone,password))
        
        return {
                'status':1,
                'errorCode':None,
                'errorMsg':None,
                'resultBody':"注册成功"
                }

      


     

                


                
            










            
















            





            

            










 
       
            


        
        


